package com.humngyang.com.hmy.controller;


import com.humngyang.com.hmy.entity.Artical;
import com.humngyang.com.hmy.service.ArticalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/ArticalController")
public class ArticalController {

    @Autowired
    ArticalService articalService;

    @RequestMapping("/addArtical")
    public Map<String,Object> addArtical(@RequestBody Artical artical) {
        articalService.addArtical(artical);
        Map map = new HashMap();
        map.put("flag",1);
        map.put("message","添加成功");
        return map;
    }


    @GetMapping("/getAllArticals")
    public Map<String,Object> getAllArticals() {
        List<Artical> allArticals = articalService.getAllArticals();
        Map map = new HashMap();
        map.put("flag",1);
        map.put("message","查询所有信息成功");
        map.put("list",allArticals);
        return map;
    }


    @RequestMapping("/getOneArticalById")
    public Map<String,Object> getOneArticalById(@RequestBody Artical artical) {
        Artical arti = articalService.getArticalbyId(artical.getId());
        Map map = new HashMap();
        map.put("flag",1);
        map.put("message","查询单个成功");
        map.put("list",arti);
        return map;
    }
}
